package dao.daoUn;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import com.datawarehouse.ScripTableUn;

import dto.bd1.ClientUN;
import dto.bd1.GiteUN;

public class SoustracteurUn {

	public List<ClientUN> getClientFromDbUN(Connection _connection)
			throws SQLException {

		List<ClientUN> list = new ArrayList<ClientUN>();
		String query = ScripTableUn.SELECT_CLIENT;
		Statement stmt = _connection.createStatement();
		ResultSet result = stmt.executeQuery(query);
		while (result.next()) {
			ClientUN client = new ClientUN();
			client.setId(result.getString("NClient"));
			client.setNom(result.getString("Nom_Client"));
			client.setPrenom(result.getString("Prenom_Client"));
			client.setNationality(result.getString("Nationalite"));
			client.setTel(result.getString("Tel"));
			client.setDateNais(result.getDate("DateNaisClient"));
			list.add(client);

		}

		return list;

	}

	public List<GiteUN> getGiteFromDbUn(Connection _con) throws SQLException {
		/*
		 * "CREATE TABLE IF NOT EXISTS  `Gite` (`id_gite` CHAR( 15 ) NOT NULL , `surface` FLOAT NOT NULL ,"
		 * +
		 * "	`Element_Descriptif` VARCHAR( 50 ) NOT NULL , `Emplacement` VARCHAR( 500 ) NOT 	NULL , `nombre_place` INT( 3 )"
		 * +
		 * " NOT NULL , `Prop` CHAR( 15 ) NOT NULL , PRIMARY KEY (`id_gite`)) ";
		 */

		List<GiteUN> listGite = new ArrayList<GiteUN>();
		String query = ScripTableUn.SELECT_GITE;
		Statement stmt = _con.createStatement();
		ResultSet result = stmt.executeQuery(query);
		while (result.next()) {
			GiteUN gite = new GiteUN();
			gite.setId(result.getString("id_gite"));
			gite.setSurface(result.getString("surface"));
			gite.setElemDescriptif(result.getString("Element_Descriptif"));
			gite.setEmplecement(result.getString("Emplacement"));
			gite.setNombrePlace(result.getInt("nombre_place"));
			gite.setProp(result.getString("Prop"));

			listGite.add(gite);
		}

		return listGite;

	}
}
